package ${package.Controller};

import com.maqh.demo.common.R;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;`
import org.springframework.web.bind.annotation.*;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.poi.ss.formula.functions.T;

import javax.annotation.Resource;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@Api(tags = {"${table.comment!}"})
@RestController
<#else>
@Controller
</#if>@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>class ${table.controllerName}<#if superControllerClass??>:${superControllerClass}()</#if><#else><#if superControllerClass??>public class ${table.controllerName} extends ${superControllerClass}{<#else>public class ${table.controllerName} {</#if>

    private Logger log = LoggerFactory.getLogger(getClass());
    @Resource
    private ${table.serviceName} ${(table.serviceName?substring(1))?uncap_first};


    @ApiOperation(value = "新增${table.comment!}")
    @PostMapping("/add")
    public R add(@RequestBody ${entity} ${entity?uncap_first}){
        try {
            return R.ok(${(table.serviceName?substring(1))?uncap_first}.add(${entity?uncap_first}));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.failed(false, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @ApiOperation(value = "删除${table.comment!}")
    @GetMapping("/delete")
    public R delete(@RequestParam("id") Long id){
        try {
            return  R.ok(${(table.serviceName?substring(1))?uncap_first}.delete(id));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.failed(false, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @ApiOperation(value = "更新${table.comment!}")
    @PostMapping("/update")
    public R update(@RequestBody ${entity} ${entity?uncap_first}){
        try {
            return R.ok(${(table.serviceName?substring(1))?uncap_first}.updateData(${entity?uncap_first}));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.failed(false, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

@ApiOperation(value = "分页查询，参数: ")
    @PostMapping("/pageList")
    public R findListByPage(@RequestBody  @Validated PageVo< T > page){
        // 此处查询参数 自己向里面规范，或者改为vo进行处理 current :当前页，size: 每页条数
        try {
            return R.ok(${(table.serviceName?substring(1))?uncap_first}.findListByPage(page));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.failed(false, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @ApiOperation(value = "id查询${table.comment!}")
    @GetMapping("/getById")
    public R findById(@RequestParam("id") Long id){
        try {
            return R.ok(${(table.serviceName?substring(1))?uncap_first}.findById(id));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.failed(false, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

}
</#if>